package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *商品模块
 * 列举所有的商品种类
 */
@Service
@Component
@Slf4j
public class ProductCateServiceImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {
        AllProductCateResponse productCateResponse = new AllProductCateResponse();
        //查询所有的商品种类
        List<ItemCat> itemCats = itemCatMapper.selectAll();
        //将List<ItemCat>转换成List<ProductCateDto>
        List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);
        productCateResponse.setProductCateDtoList(productCateDtos);
        productCateResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        productCateResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return productCateResponse;
    }
}
